﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DentScan2.WebApp
{
    public partial class SelectMethod : Classes.BaseForm
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {

                ddlAWMethods.DataSource = dl.vwMethods.Where(m => m.AreaId == this.AreaId.Value);
                ddlAWMethods.DataBind();
                if (dl.Areas.First(a => a.AreaId == this.AreaId.Value).CanCaluclateHourly)
                    ddlAWMethods.Items.Insert(0, new ListItem("ПОЧАСОВО", "-1"));
                if (Request.QueryString["NewDamage"] == "1")
                {
                    this.Damage = new Classes.Damage();
                }
            }
        }

        protected void bSelect_Click(object sender, EventArgs e)
        {
            List<string> qs = new List<string>();
            foreach (var k in Request.QueryString.AllKeys)
                qs.Add(k + "=" + Request.QueryString[k]);
            qs.Add("MethodId=" + ddlAWMethods.SelectedValue);

            if (this.Damage != null)
                this.Damage.JustHours = ddlAWMethods.SelectedValue == "-1";
            Response.Redirect("default.aspx?" + string.Join("&", qs.ToArray()));
            Response.End();
        }



    }
}